package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCarService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCarController {
    @Autowired
    private ShoppingCarService shoppingCarService;

    /**
     * 添加购物车功能
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public Result addShoppingCar(@RequestBody ShoppingCartDTO dto){
        return shoppingCarService.addShoppingCar(dto);
    }


    /**
     * 查询购物车
     * @return
     */
    @GetMapping("/list")
    public Result getShoppingCar(){
        return shoppingCarService.getShoppingCar();
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    public Result deleteAll(){
        return shoppingCarService.deleteAll();
    }

    /**
     * 单独删除购物车商品
     * @param dto
     * @return
     */
    @PostMapping("/sub")
    public Result updateNumber(@RequestBody ShoppingCartDTO dto){
        return shoppingCarService.updateNumber(dto);
    }



}
